import { api } from '@/utils/request'
import type { 
  Post, 
  PostPageParams,
  PostRequest,
  PageResult,
  ApiResponse
} from '@/types'

/**
 * 帖子管理API服务
 */
export class PostService {
  /**
   * 分页查询帖子列表
   */
  static async getPostPage(params: PostPageParams): Promise<PageResult<Post>> {
    const response = await api.post<PageResult<Post>>('/circle/api-admin/sPost/page', params)
    return response.data
  }

  /**
   * 获取帖子详情
   */
  static async getPostDetail(id: number): Promise<Post> {
    const response = await api.get<Post>(`/circle/api-admin/sPost/get/${id}`)
    return response.data
  }

  /**
   * 新增帖子
   */
  static async createPost(postData: PostRequest): Promise<boolean> {
    const response = await api.post<boolean>('/circle/api-admin/sPost/create', postData)
    return response.data
  }

  /**
   * 更新帖子
   */
  static async updatePost(postData: PostRequest): Promise<boolean> {
    const response = await api.post<boolean>('/circle/api-admin/sPost/update', postData)
    return response.data
  }

  /**
   * 删除帖子
   */
  static async deletePost(id: number): Promise<boolean> {
    const response = await api.delete<boolean>(`/circle/api-admin/sPost/delete/${id}`)
    return response.data
  }
}

// 默认导出单例实例
export const postService = PostService 